<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags/templates" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>

<c:set var="applicationPath" value="${pageContext.request.contextPath}"/>

<t:main>
    <jsp:body>
        <c:choose>
            <c:when test="${not empty subjects}">
                <table border="1">
                    <thead>
                        <tr>
                            <th><spring:message code="label.id" /></th>
                            <th><spring:message code="label.name" /></th>
                            <th><spring:message code="label.discipline" /></th>
                            <th><spring:message code="label.action" /></th>
                        </tr>
                    </thead>
                    <tbody>
                        <c:forEach items="${subjects}" var="subject" >
                        <tr>
                            <td>
                                <c:out value="${subject.id}" />
                            </td>
                            <td>
                                <c:out value="${subject.name}" />
                            </td>
                            <td>
                                <c:out value="${not empty subject.discipline ? subject.discipline.name : ''}" />
                            </td>
                            <td>
                                <a href="${applicationPath}/subject/delete/${subject.id}">
                                    <spring:message code="action.delete" />
                                </a>
                                <a href="${applicationPath}/subject/edit/${subject.id}">
                                    <spring:message code="action.edit" />
                                </a>
                            </td>
                        </tr>
                        </c:forEach>
                    </tbody>
                </table>
            </c:when>
            <c:otherwise>
                <spring:message code="alert.register.none" />
            </c:otherwise>
        </c:choose>
        <a href="${applicationPath}/subject/add/">
            <spring:message code="action.add.subject"/>
        </a>
    </jsp:body>
</t:main>